#!/bin/bash

# \e
# \033
# \x1B
Fix='033'
red='\'${Fix}'[91m'
green='\'${Fix}'[92m'
yellow='\'${Fix}'[93m'
magenta='\'${Fix}'[95m'
cyan='\'${Fix}'[96m'
none='\'${Fix}'[0m'
_version='0.01'


# if [ -z "$1"  ]
# then
#   echo "请设置命令！"
#   # exit 1;
# fi

# for i in {0..50};
# do 
#   echo -e '\\e['$i"m: \e["$i"m I love you\e[0m"

# done

# if [ -z "$2"   ]
# then
#   echo "sleep...？"
#   exit 1;
# fi

echo $1-$2

set +e

IPPrefix="192.168.8."
curPath=$(dirname $(readlink -f "$0"))
echo $curPath 
IFUSER=ceshi
PASSWD=$(cat $curPath/../.env)
# echo "PASSWD: " $PASSWD

#!/bin/bash


worker1(){
  echo
	echo
	echo -e " 进入P1P2"
  # for((i=$1;i<$2;i++));
  # for i in {101..110} 130 131 205 206 118



  echo
	while :; do
		echo -e "请输入 "$yellow"批量执行的命令"$none" "
		read -p "$(echo -e "(当前命令：${cyan}$sspass$none)"): " new_sspass
		[ -z "$new_sspass" ] && error && continue
		case $new_sspass in
		# $sspass)
		# 	echo
		# 	echo " 跟当前密码一毛一样....修改个鸡鸡哦"
		# 	error
		# 	;;
		# *[/$]*)
		# 	echo
		# 	echo -e " 由于这个脚本太辣鸡了..所以密码不能包含$red / $none或$red $ $none这两个符号.... "
		# 	echo
		# 	error
		# 	;;
		*)
			echo
			echo
			echo -e "$yellow Shadowsocks 密码 = $cyan$new_sspass$none"
			echo "----------------------------------------------------------------"
			echo

      Command {102..116} 
			# pause
			# # sed -i "48s/=$sspass/=$new_sspass/" $backup
			# backup_config sspass
			# sspass=$new_sspass
			# config
			# clear
			# view_shadowsocks_config_info
			# get_shadowsocks_config_qr_ask
			break
			;;
		esac

	done



  
}


worker2(){
  echo
	echo
	echo -e " 进入C2"
}

Command(){
  # for i in {102..116} 
  for i in $*
    do

    echo "------link--> $IPPrefix$i---------"
    # if(($i==2 || $i==34 || $i==200 || $i==14 || $i==15)); then
    #   echo "跳过 主机器..."
    #   echo "--------------------------------"
    #   echo ""
    #   continue
    # fi

    if [ -z "$2"   ]
    then
      sleep 1
    fi

    sshpass -p $PASSWD ssh -o ConnectTimeout=4 $IFUSER@$IPPrefix$i "$1"

    echo "--------------------------------"
    echo ""
  done
}


echo
# echo -e "\033[43;35m david use echo say Hello World \033[0m \n" 
# printf "\033[44;36m david use printf say Hello World \033[0m \n" 
# echo -e "\033[47;30;5m david use echo say \033[0m Hello World \n"
echo "...........  矿场部署管理脚本 $_version  .........."
echo
echo
echo -e "${green} 1. ${none}部署 Worker1 配置"
echo
echo -e "${green} 2. ${none}部署 Worker2 配置"
echo
echo -e "温馨提示...如果你不想执行选项...按$green Ctrl + C ${none}即可退出"
echo

while true ;do
 
  read -p "$(echo -e "请选择菜单 [${magenta}1-2${none}]:")" choose
  # read -p "please input the menu:cpu,mem,disk,quit: " variable
  case $choose in
    1) 
      worker1
      break
      ;;
    2) 
      worker2
      break
      ;;
    *) 
      echo
      echo  -e "  ${red}无效选项, 再来一次...${none}"
      echo
      ;;
  esac
done